home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 2 / Atari Mega Archive CD - Volume 2.iso / linux / src / atalnx_3.lzh / atari-linux-0.01pl3 / atari / atasound.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-17  |  3.1 KB  |  133 lines

  1. /*
  2.  * linux/atari/atasound.c
  3.  *
  4.  * Atari sound driver for 680x0 Linux
  5.  *
  6.  * This file is subject to the terms and conditions of the GNU General Public
  7.  * License.  See the file README.legal in the main directory of this archive
  8.  * for more details.
  9.  */
  10.  
  11. #include <linux/sched.h>
  12. #include <linux/timer.h>
  13. #include <linux/atarihw.h>
  14.  
  15. #include <asm/system.h>
  16.  
  17.  
  18. static void atari_nosound( unsigned long ignored );
  19.  
  20.  
  21. /*
  22.  * Generates sound of some count for some number of clock ticks
  23.  * [count = 1193180 / frequency]
  24.  */
  25.  
  26.  
  27. #define    PC_FREQ        1192180
  28. #define    PSG_FREQ    125000
  29.  
  30.  
  31. void atari_mksound( unsigned int count, unsigned int ticks )
  32.  
  33. {
  34.     static struct timer_list sound_timer = { NULL, 0, 0, atari_nosound };
  35.     unsigned long flags;
  36.     unsigned char tmp;
  37.  
  38.     save_flags(flags);
  39.     cli();
  40.  
  41.     if (count == 0x637 && ticks == HZ/8) {
  42.         /* Special case: These values are used by console.c to
  43.          * generate the console bell. They are catched here and the
  44.          * sound actually generated is somehow special: it uses the
  45.          * generator B and an envelope. No timer is needed therefore
  46.          * and the bell doesn't disturb an other ongoing sound.
  47.          */
  48.  
  49.         /* set envelope duration to 492 ms */
  50.         sound_ym.rd_data_reg_sel = 11;
  51.         sound_ym.wd_data = 0;
  52.         sound_ym.rd_data_reg_sel = 12;
  53.         sound_ym.wd_data = 15;
  54.         /* envelope form: max -> min single */
  55.         sound_ym.rd_data_reg_sel = 13;
  56.         sound_ym.wd_data = 9;
  57.         /* set generator B frequency to 2400 Hz */
  58.         sound_ym.rd_data_reg_sel = 2;
  59.         sound_ym.wd_data = 52;
  60.         sound_ym.rd_data_reg_sel = 3;
  61.         sound_ym.wd_data = 0;
  62.         /* set volume of generator B to envelope control */
  63.         sound_ym.rd_data_reg_sel = 9;
  64.         sound_ym.wd_data = 0x10;
  65.         /* enable generator B in the mixer control */
  66.         sound_ym.rd_data_reg_sel = 7;
  67.         tmp = sound_ym.rd_data_reg_sel;
  68.         sound_ym.wd_data = (tmp & ~0x02) | 0x38;
  69.  
  70.         restore_flags(flags);
  71.         return;
  72.     }
  73.  
  74.     del_timer( &sound_timer );
  75.  
  76.     if (!count) {
  77.         atari_nosound( 0 );
  78.     }
  79.     else {
  80.  
  81.         /* convert from PC counter value (base frequency 1.193 MHz) to PSG
  82.          * period value (base frequency 125 kHz).
  83.          */
  84.         int        period = (PSG_FREQ * count + PC_FREQ/2) / PC_FREQ;
  85.  
  86.         if (period > 0xfff) period = 0xfff;
  87.  
  88.         /* set generator A frequency to 0 */
  89.         sound_ym.rd_data_reg_sel = 0;
  90.         sound_ym.wd_data = period & 0xff;
  91.         sound_ym.rd_data_reg_sel = 1;
  92.         sound_ym.wd_data = (period >> 8) & 0xf;
  93.         /* turn on generator A in mixer control (but not noise
  94.          * generator!) */
  95.         sound_ym.rd_data_reg_sel = 7;
  96.         tmp = sound_ym.rd_data_reg_sel;
  97.         sound_ym.wd_data = (tmp & ~0x01) | 0x38;
  98.         /* set generator A level to maximum, no envelope */
  99.         sound_ym.rd_data_reg_sel = 8;
  100.         sound_ym.wd_data = 15;
  101.         
  102.         if (ticks) {
  103.             sound_timer.expires = ticks;
  104.             add_timer( &sound_timer );
  105.         }
  106.     }
  107.  
  108.     restore_flags(flags);
  109. }
  110.  
  111.  
  112. static void atari_nosound( unsigned long ignored )
  113.  
  114. {    unsigned char    tmp;
  115.     
  116.     /* turn off generator A in mixer control */
  117.     sound_ym.rd_data_reg_sel = 7;
  118.     tmp = sound_ym.rd_data_reg_sel;
  119.     sound_ym.wd_data = tmp | 0x39;
  120. }    
  121.         
  122.  
  123. void atari_microwire_cmd( int cmd )
  124.  
  125. {
  126.     tt_microwire.mask = 0x7ff;
  127.     tt_microwire.data = MW_LM1992_ADDR | cmd;
  128.  
  129.     /* Busy wait for data being completely sent :-( */
  130.     while( tt_microwire.mask != 0x7ff)
  131.         ;
  132. }
  133.